package t4invoke;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import t4bean.FruitBean;
import t4bean.MoneyRecordBean;
import t4bean.PurchaseRecordBean;
import t4dao.FruitDao;
import t4dao.MoneyRecordDao;
import t4dao.PurchaseRecordDao;

public class ShowFruitAction implements Action {
	@Override
	public void showFruit() {
		FruitDao fd = new FruitDao();
		List<FruitBean> list = new ArrayList<>();
		try {
			list = fd.select(null);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		List<MoneyRecordBean> moneylist = null;
		List<PurchaseRecordBean> purchaselist = null;
		MoneyRecordDao mrd = new MoneyRecordDao();
		PurchaseRecordDao prd = new PurchaseRecordDao();
		MoneyRecordBean mrb = new MoneyRecordBean();
		PurchaseRecordBean prb = new PurchaseRecordBean();

		for (FruitBean fruit : list) {
			mrb.setFruitName(fruit.getName());
			try {
				moneylist = mrd.select(mrb);
			} catch (SQLException e) {
				e.printStackTrace();
			}
			Integer sellnumber = 0;
			for (MoneyRecordBean mrb1 : moneylist) {
				sellnumber += mrb1.getNumber();
			}
			prb.setFruitName(fruit.getName());
			try {
				purchaselist = prd.select(prb);
			} catch (SQLException e) {
				e.printStackTrace();
			}
			Integer purchasenumber = 0;
			for (PurchaseRecordBean prb1 : purchaselist) {
				purchasenumber += prb1.getNumber();
			}

			System.out.println("水果种类：" + fruit.getName());
			System.out.println("水果库存：" + fruit.getNumber());
			System.out.println("水果进价：" + fruit.getCost());
			System.out.println("水果售价：" + fruit.getPrice());
			System.out.println("水果卖出数量：" + sellnumber);
			System.out.println("水果卖出金额：" + sellnumber * fruit.getPrice());
			System.out.println("水果进货数量：" + purchasenumber);
			System.out.println("水果进货花费：" + purchasenumber * fruit.getCost());
			System.out.println();
		}
	}

	@Override
	public void sell(Scanner sc) {

	}

	@Override
	public void purchase(Scanner sc) {

	}

	@Override
	public void moneyGet(Scanner sc) {

	}

	@Override
	public void showAllSellRecord() {

	}

	@Override
	public void three() {

	}

}
